package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"unicode"
)

type CharCount struct {
	WordCount  int
	NumCount   int
	SpaceCount int
	Chinese    int
	OtherCount int
}

func main() {
	// 文件字符统计
	// 每读取一行就去统计多少 英文，数字，空格和其他字符
	path := "d:/abc.txt"
	file, err := os.Open(path)
	if err != nil {
		fmt.Println("Open file error", err)
		return
	}
	defer file.Close()

	var count CharCount

	reader := bufio.NewReader(file)
	for {
		str, err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		for _, v := range str {
			switch {
			case v >= 'a' && v <= 'z':
				fallthrough // 穿透
			case v >= 'A' && v <= 'Z':
				count.WordCount++
			case v == ' ' || v == '\t':
				count.SpaceCount++
			case v >= '0' && v <= '9':
				count.NumCount++
			case unicode.Is(unicode.Han, v):
				count.Chinese++
			default:
				count.OtherCount++
			}
			fmt.Println(v)
		}
	}
	fmt.Println(count)
}
